<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
	workSeq		= Request("workSeq")
	rcvrId			= Request("rcvrId")
	
	setUser	= Request("setUser")	'권한 위임
	
	if setUser = "" then 
		updateSql = "UPDATE tblWorkBbsRcvr SET openDt = getdate() WHERE openDt IS NULL AND rcvrId='" & Request.Cookies("S_uid") & "'"
		DbCon.Execute updateSql
	end if 
	
	SQLTitle = "-- ■■■■  문서 상세 정보 ■■■■"
	
	SQL = "SELECT B.userNm, A.workSeq, A.subjects, A.writeId, CONVERT(varchar(16), A.writeDt, 121) writeDt, CONVERT(varchar(16), A.modDt, 121) modDt, A.endDt, A.contents, A.files, A.flag " & _
			"	FROM tblWorkBbs A LEFT JOIN tblUser B ON A.writeId=B.userId WHERE A.workSeq=" & workSeq

	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 

	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Rs.open SQL, DbCon, 1
	
	Response.write "<WorkDetail>" & vbcrlf

	If Rs.eof Or Rs.bof Then 
	Else 
		Do Until Rs.eof Or Rs.bof
		
			Call mkXMLNode("workSeq", rs("workSeq"), 1)
			Call mkXMLNode("userNm", rs("userNm"), 1)
			Call mkXMLNode("subjects", rs("subjects"), 1)
			Call mkXMLNode("writeDt", rs("writeDt"), 1)
			Call mkXMLNode("modDt", rs("modDt"), 1)
			Call mkXMLNode("endDt", rs("endDt"), 1)
			Call mkXMLNode("contents", rs("contents"), 1)
			Call mkXMLNode("writeId", rs("writeId"), 1)
			Call mkXMLNode("files", rs("files"), 1)
			Call mkXMLNode("flag", Rs("flag"), 1)
		Rs.movenext
		Loop 
	End If
	
	'## 수신자 정보 조회
	addSql = ""
	if rcvrId <> "" and rcvrId <> "undefined" then
		if setUser = "" then 
			addSql = " AND A.rcvrId='" & rcvrId & "' "
		else 
			addSql = " AND A.rcvrId='" & setUser & "' "
		end if  
	end if 
	rcvrSql = "SELECT B.userNm, " & _
				"		CASE WHEN A.completeDt IS NOT NULL  THEN '완료: '+RIGHT(CONVERT(varchar(16), A.completeDt, 121),11) " & _
				"				 WHEN A.knowDt IS NOT NULL THEN '진행: '+ RIGHT(CONVERT(varchar(16), A.knowDt, 121),11) " & _  
				"				 WHEN A.openDt IS NOT NULL THEN '인지: '+ RIGHT(CONVERT(varchar(16), A.openDt, 121),11) " & _
				"				 ELSE '미인지' END vStatus, " & _
				"		CASE WHEN A.completeDt IS NOT NULL  THEN '완료' " & _
				"				 WHEN A.knowDt IS NOT NULL THEN '진행' " & _  
				"				 WHEN A.openDt IS NOT NULL THEN '인지' " & _
				"				 ELSE '미인지' END status " & _
				"	FROM tblWorkBbsRcvr A LEFT JOIN tblUser B ON A.rcvrId=B.userID WHERE A.workSeq=" & workSeq & addSql
				
	If xMode="debug" Then 
		Call showDebug(SQLTitle & "수신자 정보",rcvrSql) 
	End If 

	Set rcvrRs=Server.CreateObject("ADODB.RecordSet")
	rcvrRs.open rcvrSql, DbCon, 1
	
	If rcvrRs.eof Or rcvrRs.bof Then 
	Else 
		Do Until rcvrRs.eof Or rcvrRs.bof
			if rcvrs <> "" then rcvrs = rcvrs & ", "
			rcvrs = rcvrs & "<b>" & rcvrRs("userNm") & "</b>(" & rcvrRs("vStatus") & ")"
			status = ""
			if rcvrId <> "" and rcvrId <> "undefined" then
				status = rcvrRs("status")			'## 수신문서 상태 정보
			end if
		rcvrRs.movenext
		Loop 
	End If
	
		Call mkXMLNode("rcvrs", rcvrs, 1)
		Call mkXMLNode("status", status, 1)
				  
	Response.write "</WorkDetail>" & vbcrlf
'	Call rsWithXML("Save OK!")
%>